package models.common.bean.receivable;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Transient;

import common.constants.ConfConst;
import common.constants.Constants;
import common.enums.Type;
import common.utils.Security;
import common.utils.number.Arith;

/**
 * 商票挂牌初始化信息
 *@author liaijun
 *@version 2018年1月16日 下午4:24:23
 */
@Entity
public class PaperInfoToLoadBid {
 
	@Id
	public Long id;
	
	/**背书id，避免id与其他id重复*/
	public long eid;
	
	/**
	 * 商票金额
	 */
	public Double paper_money;
	/**
	 * 商票到期日期
	 */
	public Date paper_expire_time;
	/**
	 * 商票出票时间'
	 */
	public Date paper_create_time;
	
	/**
	 * 凭证号码
	 */
	public String bill_code;
	
	/**
	 * 商票的类型 1,商票质押融通 3 背书，4数字商票
	 */
	public int type;
	
	  /**商票质押融通融通比例*/
    public double finacing_ratio;
	
    /**商票质押融通已使用金额*/
    public double  finacing_used_limit;
    
    /**背书/数字商票融通额度*/
    public double finacing_limit;
    
    /**商票可用金额*/
    public double finacing_residue_limit;
    
    
	@Transient
	public String sign;
	public String getSign(){
	  return Security.addSign(this.id, Constants.BID_ID_SIGN, ConfConst.ENCRYPTION_KEY_DES);
	}
	
	@Transient
	public String endoseSign;
	public String getEndoseSign(){
		return Security.addSign(this.eid, Constants.BID_ID_SIGN, ConfConst.ENCRYPTION_KEY_DES);
	}
	
	@Transient
	public Type paperType;
	public Type getPaperType(){
		return Type.getEnum(type);
	}
	
	//可融通最大额度
	@Transient
	public double amountMax;
	
	public double getAmountMax(){
		double amount = 0;
		switch (type) {
		case 1:
			amount = Arith.sub(Arith.mul(finacing_ratio/100, paper_money), finacing_used_limit);
			break;
		case 3:
			amount = finacing_limit;
			break;
		case 4:
			amount = Arith.div(Arith.mul(paper_money, finacing_ratio),100,2);
			break;
		default:
			amount = 0;
			break;
		}
		//amount = Arith.sub(Arith.mul(finacing_ratio/100, paper_money), finacing_used_limit);
		
		return amount > finacing_residue_limit ? finacing_residue_limit : amount;
	}
}
